<table class="ui celled striped table">
    <thead>
      <tr>
        <th>Author</th>
        <th>Title</th>
        <th>Create Time</th>
        <th>Publish Time</th>
        <th></th>
      </tr>
    </thead>

    <tbody>
    <%= for post <- @posts do %>
      <tr>
        <td class="center aligned">
          <%= link to: Routes.admin_person_path(@conn, :show, post.author) do %>
            <img class="ui avatar image" src="<%= ChangelogWeb.PersonView.avatar_url(post.author) %>">
          <% end %>
        </td>
        <td><%= SharedHelpers.truncate(post.title, 100) %></td>
        <td><%= AdminHelpers.ts(post.inserted_at) %></td>
        <td><%= AdminHelpers.ts(post.published_at) %></td>
        <td class="center aligned">
          <div class="ui small basic buttons">
            <%= AdminHelpers.icon_link("eye", to: show_or_preview_path(@conn, post)) %>
          <%= if Policies.Admin.Post.edit(@current_user, post) do %>
            <%= AdminHelpers.icon_link("edit", to: Routes.admin_post_path(@conn, :edit, post)) %>
          <% end %>
          <%= if Policies.Admin.Post.delete(@current_user, post) do %>
            <%= AdminHelpers.icon_link("trash",
                          to: Routes.admin_post_path(@conn, :delete, post),
                          method: :delete,
                          data: [confirm: "Are you sure?"]) %>
          <% end %>
          </div>
        </td>
      </tr>
    <% end %>
    </tbody>
  </table>
